package cmpe273.classproject.testclient;

import java.rmi.RemoteException;
import java.util.Calendar;

import org.junit.Test;
import static org.junit.Assert.*;
import cmpe273.classproject.server.dto.MovieResponse;
import cmpe273.classproject.server.model.Movie;
import cmpe273.classproject.server.model.Person;
import cmpe273.classproject.server.service.MovieServiceImplProxy;

public class TestService {

	private MovieServiceImplProxy ms;
	
	public TestService() {
		ms = new MovieServiceImplProxy();
	}
	
	@Test
	public void testCreateMovie() {
		
	}
	
	@Test
	public void testGetAllMovies() {
		
	}
	
	@Test
	public void testUpdateMovie() throws RemoteException {
		Movie m = new Movie();
		m.setMovieId(12);
		m.setAvailableCopy(-1);
		m.setMovieCategory("Drama");
		m.setMovieName("Update movie !!!");
		m.setMovieBanner("CHANGED TEST HI PARAG");
		ms.updateMovie(m);
	}
	
	@Test
	public void testFindMovie() throws RemoteException {
		Movie m = new Movie();
		Calendar cal = Calendar.getInstance();
		cal.set(2009, 11, 11);
		m.setReleaseDate(cal);
		MovieResponse mr = ms.findMovie(m);
		System.out.println();
		assertEquals(4, mr.getMovies().length);
	}
	
	@Test
	public void testIssueMovieAlreadyIssued() throws RemoteException {
		Movie m = new Movie();
		Person p = new Person();
		p.setMemberId(14);
		m.setMovieId(12);
		MovieResponse mr = ms.issueMovie(m, p);
		assertEquals(-1, mr.getError());
		System.out.println(mr.getErrorMessage());
	}
	
	@Test
	public void testIssueMoviePremiumMember() throws RemoteException {
		Movie m = new Movie();
		Person p = new Person();
		p.setMemberId(1232);
		m.setMovieId(200);
		MovieResponse mr = ms.issueMovie(m, p);
		assertEquals(0, mr.getError());
	}
}
